package controller

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"kf/models/dao"
	"kf/tools"
)

type NoticeController struct {
	SysUserDao      *dao.SysUserDao
	SysAutoReplyDao *dao.SysAutoReplyDao
	Log             *zap.Logger
}

// 获取notice
func (noticeController *NoticeController) GetNotice(c *gin.Context) {
	kefuId := c.Query("kefu_id")
	//获取语言
	lang := tools.GetLang(c)
	user, err := noticeController.SysUserDao.FindSysUserById(kefuId)
	if err != nil || user.ID == 0 {
		c.JSON(200, gin.H{
			"code": 400,
			"msg":  "user not found",
		})
		return
	}
	welcomeMessage := noticeController.SysAutoReplyDao.FindAutoReply("WelcomeMessage", lang)
	offlineMessage := noticeController.SysAutoReplyDao.FindAutoReply("OfflineMessage", lang)
	allNotice := noticeController.SysAutoReplyDao.FindAutoReply("AllNotice", lang)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "ok",
		"result": gin.H{
			"config":    welcomeMessage,
			"offline":   offlineMessage,
			"avatar":    user.Avatar,
			"nickname":  user.NickName,
			"allNotice": allNotice,
		},
	})
}
